import Vue from 'vue'

const gotResponse = ({code, message, data}) =>{
  if(code == 200) {
    return Promise.resolve(data)
  }else if(code == 501){
    return Promise.reject(message)
  }else {
    return Promise.reject(message)
  }
}
const responseError = (e)=>{
  return Promise.reject(e.message || e.toString())
}

const post = (url, params) => {
  return Vue.prototype.$post(url, params)
  .then(gotResponse)
  .catch(responseError)
}
const get = (url, params) => {
  return Vue.prototype.$get(url, {params})
  .then(gotResponse)
  .catch(responseError)
}

export const api = {
  user: {
    login(params) {
      return post('/user/authPass', params)
    },
    updatePass(params){
      return post('/user/updatePass', params)
    },
    register(params) {
      return post('/user/regist', params)
    },
    list(params) {
      return post('/account/wxAccountsByCsId', params)
    },
    updateWxAccount(params){
      return post('/account/updateWxAccount', params)
    },
    // body:{"wxAccount" : "}
    sync(params){
      return post('/account/sync', params)
    }
  },
  friend: {
    // 好友列表
    list(params) {
      return post('/friend/friends', params)
    },
    // 会话好友列表
    chatFriends(params) {
      return post('/friend/chatFriends', params)
    },

    cancel(params) {
      return post('/friend/cancel', params)
    },
    // 查询好友设置
    getInviteSetting(params) {
      return post('/invite/getInviteSetting', params)
    },
    // 添加设置
    insertInviteSetting(params) {
      return post('/invite/insertInviteSetting', params)
    },
    // 邀请记录列表
    inviteFriendHistory(params) {
      return post('/invite/inviteFriendHistory', params)
    },
    // 添加批量任务
    inviteFriend(params) {
      return post('/friend/inviteFriend', params)
    },
    // 更新设置
    updateInviteSetting(params) {
      return post('/invite/updateInviteSetting', params)
    },
    //取得用户详细数据
    getFriendDetail(params) {
      return post('/friend/friendDetail',params)
    },
    // 获取用户会员列表
    getVipFriendInfo(params){
      return post('/friend/getVipFriendInfo',params)
    }
  },
  chat:{
    // 删除会话
    removeChatList(params){
      return post('/chat/remove_chat_list', params)
    },
    // 会话聊天记录
    chatList(params) {
      return post('/chat/list_chats', params)
    },
    // 根据名片加好友
    acceptCard(params){
      return post('/chat/accept_card',params)
    },
    // 通知会话已读
    readChat(params){
      return post('/chat/readChat',params)
    },
    // 插入标签tag
    insertFriendTag(params){
      return post('/chat/insertFriendTag',params)
    },
    // 查询标签
    friendTag(params){
      return post('/chat/friendTag',params)
    },
     // 删除标签
    delFriendTag(params){
      return post('/chat/del',params)
    },
    // 修改备注
    editFriend(params){
      return post('/chat/editFriend',params)
    },
    // 设置VIP 屏蔽
    topAndStatus(params){
      return post('/chat/isTop-status',params)
    },
    // 扫描图片中二维码, 参数以json格式，进行post, 需要chatId， messsage, csId
    scanImage(params){
      return post('/chat/scan_image',params)
    },
    // /chat/show_qrcode.kf
    showQrcode(params){
      return post('/chat/show_qrcode.kf',params)
    },
    joinGroup(params){
      return post('/chat/joinGroup',params)
    },
    // 撤回
    revokeMsg(params){
      return post('/chat/revokeMsg',params)
    }


  },
  groupKeyword:{
    insert(params){
      return post('/groupKeyword/insert',params)
    },
    get(params){
      return post('/groupKeyword/get',params)
    },
    del(params){
      return post('/groupKeyword/del',params)
    },
    update(params){
      return post('/groupKeyword/update',params)
    }
  },
  validation: {
    // 获取设置推荐值
    get(params) {
      return post('/validation/get', params)
    },
    // 验证
    insert(params) {
      return post('/validation/insert', params)
    },
    // 好友验证列表
    list(params) {
      return post('/validation/list', params)
    },
    insertSetting(params){
      return post('/validation/insertSetting',params)
    },
    sync(params){
      return post('/validation/sync',params)
    },


  },
  groupSend: {
    cancel(params) {
      return post('/msg/cancel', params)
    },
    delete(params) {
      return post('/msg/del', params)
    },
    send(params) {
      return post('/msg/insetMsgTask', params)
    },
    list(params) {
      return post('/msg/msgTaskList', params)
    },
    update(params) {
      return post('/msg/updateMsg', params)
    },
    listTaskDetail(params){
      return post('/msg/listTaskDetail',params)
    }
  },
  newResponse:{
    get(params){
      return post('/newResponse/get',params)
    },
    del(params){
      return post('/newResponse/del',params)
    },
    insert(params){
      return post('/newResponse/insert',params)
    },
    update(params){
      return post('/newResponse/update',params)
    },
  },
  timeline:{
    cancelTimeline(params){
      return post('/timeline/cancelTimeline',params)
    },
    createTimeline(params){
      return post('/timeline/createTimeline',params)
    },
    getTimelines(params){
      return post('/timeline/getTimelines',params)
    },
    // 查看朋友圈
    commentFriendLine(params){
      return post('/timeline/commentFriendLine',params)
    },
    getFriendTimelines(params){
      return post('/timeline/getFriendTimelines',params)
    },
    getTimelineByTid(params){
      return post('/timeline/getTimelineByTid',params)
    },

    getTimelineFileUrls(params){
      return post('/timeline/getTimelineFileUrls',params)
    },
    refreshFriendTimeline(params){
      return post('/timeline/refreshFriendTimeline',params)
    },
    sendLike(params){
      return post('/timeline/sendLike',params)
    },
    uncommentFriendLine(params){
      return post('/timeline/uncommentFriendLine',params)
    }



  },
  groupTask:{
    // 新建插入设置csid, accountwxid,
    // taskType 0:建讨论组 1:建群, secondWxAccount 辅助账号,
    // memberType 0：搜索 1:好友 2：群成员,
    // searchNameList 群成员搜索名列表,
    // inviteFriendList 邀请的friend列表,
    // inviteGroupFriendList 邀请的群列表,
    // groupname 讨论组或者群名称
    insert(params){
      return post('/groupTask/insert',params)
    },
    cancel(params){
      return post('/groupTask/cancel',params)
    },
    getSendList(params){
      return post('/groupTask/getSendList',params)
    }
  },
  group: {
    // 群列表
    list(params) {
      return post('/group/groups', params)
    },
    // 群成员
    members(params) {
      return post('/group/groupMember', params)
    },
    //
    addFriend2Group(params) {
      return post('/group/addFriend2Group', params)
    },
    membersByGroupNoList(params){
      return post('/group/groupMemberByGroupNoList',params)
    },
    dismiss(params) {
      return post('/group/dissGroup', params)
    },
    // 查找该wxid所在的所以微信群
    groupsForMemeber(params){
      return post('/group/groupsForMemeber', params)
    },
    removeMember(params) {
      return post('/group/removeGroup', params)
    },
    removeGroupMember(params) {
      return post('/chat/removeGroupMember', params)
    },
    quitGroup(params){
      return post('/chat/quitGroup',params)
    },
    // 修改群名称
    setGroupName(params){
      return post('/chat/setGroupName',params)
    },
    // 群资料
    groupInfo(params){
      return post('/group/groupInfo',params)
    },
    //邀请记录
    groupInviteHistory(params){
      return post('/group/groupInviteHistory',params)
    },
    // 群邀请
    sendGroupInvite(params){
      return post('/chat/invite_groups',params)
    },
    groupQrcode(params){
      return post('/group/groupQrcode',params)
    },
    // 群成员黑名单
    addBlacklist(params){
      return post('/group/addblacklist',params)
    },
    groupBlacklist(params){
      return post('/group/blacklist',params)
    }
  },
  keyword: {
    list(params) {
      return post('/keyword/list', params)
    },
    getSetting(params) {
      return post('/keyword/getSetting', params)
    },
    insert(params) {
      return post('/keyword/insertSetting', params)
    },
    deleteSetting(params) {
      return post('/keyword/delRecord', params)
    },
    deleteRecord(params) {
      return post('/keyword/delRecord', params)
    },
    updateSetting(params) {
      return post('/keyword/updateSetting', params)
    }
  },
  tag: {
    list(params) {
      return post('/tag/list', params)
    },
    insert(params) {
      return post('/tag/insertSetting', params)
    },
    getSetting(params) {
      return post('/tag/getSetting', params)
    },
    delete(params) {
      return post('/tag/del', params)
    }
  },
  rule: {
    whiteList(params) {
      return post('/rule/whiteList', params)
    },
    getSetting(params) {
      return post('/rule/get', params)
    },
    deleteSetting(params) {
      return post('/rule/del', params)
    },
    insertSetting(params) {
      return post('/rule/insert', params)
    },
    addWhiteList(params) {
      return post('/rule/addWhite', params)
    },
    removeWhiteList(params) {
      return post('/rule/removeWhite', params)
    },
    history(params) {
      return post('/rule/recordHistory', params)
    }
  },
  welcome: {
    list(params) {
      return post('/welcome/welcomeList', params)
    },
    getSetting(params) {
      return post('/welcome/getSetting', params)
    },
    insert(params) {
      return post('/welcome/insertSetting', params)
    },
    update(params) {
      return post('/welcome/update', params)
    },
    delete(params) {
      return post('/welcome/del', params)
    },
    cancel(params) {
      return post('/welcome/cancel', params)
    }
  },
  phrase:{
    get(params){
      return post('/phrase/get', params)
    },
    add(params){
      return post('/phrase/add', params)
    },
    del(params){
      return post('/phrase/del', params)
    },
    getlimit(params){
      return post('/phrase/getlimit',params)
    },
    getReplyPhrase(params){
      return post('/phrase/getReplyPhrase',params)
    },
    saveReplyPhrase(params){
      return post('/phrase/saveReplyPhrase',params)
    },
    deleteReplyPhase(params){
      return post('/phrase/deleteReplyPhase',params)
    },
  },
  acitvecode:{
    save(params){
      return post('/acitvecode/save',params)
    },
    getRecords(params){
      return post('/acitvecode/getRecords',params)
    },
    getActiveQrcode(params){
      return get('/acitvecode/getActiveQrcode',params)
    }
  },
  award:{
    saveGroupAward(params){
      return post('/award/saveGroupAward',params)
    },
    getRecords(params){
      return post('/award/getGroupAwardList',params)
    },
    deleteRecord(params){
      return post('/award/deleteAward',params)
    }
  }
}

export default {
  install(Vue, options) {
    Vue.prototype.$api = api
  }
}
